﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;

namespace TiposComuns.Objectos
{
    [Serializable]
    public class IDMsg : IComparable<IDMsg>
    {
        public int ID
        {
            [MethodImpl(MethodImplOptions.Synchronized)]
            get;
            [MethodImpl(MethodImplOptions.Synchronized)]
            set;
        }

        public bool isClient
        {
            [MethodImpl(MethodImplOptions.Synchronized)]
            get;

            [MethodImpl(MethodImplOptions.Synchronized)]
            set;
        }


        public IDMsg()
        {
            ID = 0;
            isClient = true;
        }

        public IDMsg(int id, bool cliente)
        {
            ID = id;
            isClient = cliente;
        }

        #region Methods

        
        public void Inc()
        {
            ID++;
        }

        
        public void Dec()
        {
            ID--;
        }

        public override string ToString()
        {
            return (this.ID.ToString()+(this.isClient.ToString()));
        }

        public override int GetHashCode()
        {
            string s = this.ID.ToString() + this.isClient.ToString();
            return s.GetHashCode();
        }
        #endregion


        #region IComparable<IDMsg> Members

        public int CompareTo(IDMsg other)
        {
            if (this.ID != other.ID)
            {
                return (this.ID < other.ID) ? -1 : 1;
            }
            else
            {
                return this.isClient.CompareTo(other.isClient);
            }
        }

        public IDMsg Clone()
        {
            return new IDMsg(this.ID, this.isClient);
        }
        #endregion
    }
}
